package com.iapp.service.impl;

import com.iapp.mapper.AdminUserMapper;
import com.iapp.po.AdminUser;
import com.iapp.po.Result;
import com.iapp.service.AdminUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Component
public class AdminUserServiceImpl implements AdminUserService {
    @Resource
    private AdminUserMapper adminUserMapper;


    @Override
    public Result insertAdminUser(AdminUser adminUser) {
        AdminUser user=adminUserMapper.getAdminUserByName(adminUser.getAdminName());
        if(user!=null){
            return new Result().fail("注册失败","账号名已存在");
        }
        Integer res=adminUserMapper.insertAdminUser(adminUser);
        if(res<=0){
            return new Result().fail("注册失败");
        }
        return new Result().success("注册成功");
    }

    @Override
    public Result getAdminUserByName(String adminName,String adminPass) {
        AdminUser adminUser=adminUserMapper.getAdminUserByName(adminName);
        if(adminUser==null){
            return new Result().fail("失败","用户名不存在");
        }else if(!adminUser.getAdminPass().equals(adminPass)){
            return new Result().fail("失败","密码不正确");
        }
        return new Result().success("登陆成功",adminUser);
    }
}
